﻿using MediatR;
using T.Basic.API.Appliction.Command.CargoOwnerCommand;
using T.Basic.Repository.BasicInterface;

namespace T.Basic.API.Appliction.CommandHandlers.CargoOwnerHanders
{
    /// <summary>
    /// 批量删除货主信息
    /// </summary>
    public class CargoOwnerDeleteAllCommandHandler : IRequestHandler<CargoOwnerDeleteAllCommand, int>
    {
        private readonly ICargoOwnerRepository _CargoOwnerrepository;
        public CargoOwnerDeleteAllCommandHandler(ICargoOwnerRepository cargoOwnerrepository)
        {
            _CargoOwnerrepository = cargoOwnerrepository;
        }
        public async Task<int> Handle(CargoOwnerDeleteAllCommand request, CancellationToken cancellationToken)
        {
            var ids = request.CargoOwnerIds;
            foreach (var item in ids)
            {
                var DelCargoOwner = _CargoOwnerrepository.GetModelsAsync(item).Result;
               
                DelCargoOwner.IsDeleted = true;
               await _CargoOwnerrepository.UpdateAsync(DelCargoOwner);
            }
            return 1;
        }
    }
}
